<?php

class ZFKiller_Controller extends Zend_Controller_Action {
    
    public function init() {
		parent::init();

		Zend_Controller_Action_HelperBroker::addPath(
				PATH_ZFEXTEND . '/ZFKiller/Controller/Action/Helper', 'ZFKiller_Controller_Action_Helper'
		);
	}

	protected function noRender() {
		$this->_helper->layout()->disableLayout();
		$this->_helper->viewRenderer->setNoRender(true);
	}

	public static function getUriFormat($uri, $options) {
		if (null === $options) {
			return $uri;
		}
		
		foreach ($options as $key => $option) {
			$options['{{' . $key . '}}'] = $option;
			unset($options[$key]);
		}
		return strtr($uri, $options);
	}
    
    protected function markActiveNav($search, $type = 'id') {
		$container = $this->view->navigation()->getContainer();
		
		if (is_array($search)) {
			$activeNav = $container;

			foreach ($search as $item) {
				$activeNav = $activeNav->findOneBy($item[1], $item[0]);
				if ($activeNav === null) {
					break;
				}
			}
		}
		else {
			$activeNav = $container->findOneBy($type, $search);
		}
		if (null !== $activeNav) {
			$activeNav->active = true;
			$activeNav->setClass('active');
		}
	}

}